from flask import Blueprint, request, jsonify
from app.services import StudentService

bp = Blueprint('student', __name__)

@bp.route('', methods=['POST'])
def create_student():
    """创建学生账号"""
    data = request.get_json()
    result = StudentService.create_student(
        parent_id=data.get('parent_id'),
        name=data.get('name'),
    )
    return jsonify(result), result['code']

@bp.route('', methods=['GET'])
def get_students():
    """获取学生列表"""
    parent_id = request.args.get('parent_id', type=int)
    result = StudentService.get_student_list(parent_id=parent_id)
    return jsonify(result), result['code']

@bp.route('/<int:student_id>', methods=['PUT'])
def update_student(student_id):
    """修改学生信息"""
    result = StudentService.update_student_info(
        student_id=student_id,
        **request.get_json()
    )
    return jsonify(result), result['code']

@bp.route('/<int:student_id>', methods=['DELETE'])
def delete_student(student_id):
    """删除学生信息"""
    result = StudentService.delete_student(student_id=student_id)
    return jsonify(result), result['code']

# 删除多个学生
@bp.route('', methods=['DELETE'])
def delete_students():
    """删除多个学生信息"""
    result = StudentService.delete_students(
        student_ids=request.get_json().get('student_ids')
    )
    return jsonify(result), result['code']
@bp.route('/account-info/<int:student_id>', methods=['GET'])
def get_student_account_info(student_id):
    """获取学生账号信息"""
    result = StudentService.get_student_account_info(student_id=student_id)
    return jsonify(result), result['code']